/*

Stickman Adventure - a game created by Daco & his cousin

Copyright (C) 2011-2012  DacoTaco & Wouterke

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


*/
#include "Vegeta.h"

//Player::Player(SDL_Surface *spritesheet,int xpos , int ypos , Mix_Chunk *sound ) : MovingObject(spritesheet,xpos , ypos ,192,64 ,OBJECT_PLAYER,sound )
Foo::Foo(char* spritesheet,int xpos , int ypos) : MovingObject(spritesheet,xpos , ypos ,154,123,OBJECT_BACKGROUND ,NULL,NULL)
{ 
	//Initialize movement variables 
	offSet = 0; velocity = 1; 
	//Initialize animation variables 
	frame = 0; 
	status = 1; 
	pAnimation = NULL;
	ResizeImage(1,1);
}
Foo::~Foo()
{
	if(pAnimation)
		SDL_FreeSurface( pAnimation );
	return;
}
void Foo::ResizeImage(double x, double y)
{
	if(sheet == NULL)
	{
		clip[0].x = Foo::x;
		clip[0].y = Foo::y;
		clip[0].h = 154;
		clip[0].w = 123;
		return;
	}
	if(pAnimation)
		SDL_FreeSurface( pAnimation );
	pAnimation = rotozoomSurfaceXY(sheet,0,x,y,1);
	for(int z = 0;z<62;z++)
	{
		//Clip range for the top left 
		clip[ z ].x = (int)(((double)pAnimation->w/62)*z); 
		clip[ z ].y = 0; 
		clip[ z ].w = (pAnimation->w/62); 
		clip[ z ].h = (pAnimation->h); 
	}
}
SDL_Rect* Foo::getImageClip()
{
	return &clip[frame];
}
/*SDL_Rect* Foo::GetColRect()
{
	ColRect.x = (int)(video.SCREEN_WIDTH / offset_x)-((pAnimation->w / 62)/2);
	ColRect.y = (int)(video.SCREEN_HEIGHT / offset_y)-(pAnimation->h);
	ColRect.h = pAnimation->h;
	ColRect.w = pAnimation->w / 62;
	return &ColRect;
}*/
void Foo::SetCoordinates(double x, double y) 
{ 
	offset_x = x;
	offset_y = y;
	return;
	//Move 
	offSet += velocity; 
	//Keep the stick figure in bounds 
	if( ( offSet < 0 ) || ( offSet + (pAnimation->w/62) > 1280 ) ) 
	{ 
		offSet -= velocity; 
	} 
}
char Foo::Update(int collision, int y_ground, int x_wall)
{
	if(sheet == NULL)
		return 1;
	else if(velocity == 0)
	{
		//act normal, no frame limit	
		status = 1; 
		//Move to the next frame in the animation 
		frame++; 
	}
	else if( velocity > 0 ) 
	{ 
		//there is a limit. o noez
		if(status == 1)
		{
			//Move to the next frame in the animation 
			frame++;
			status = 0;
		}
		else
			status++;
	} 
	//If Foo standing 
	else 
	{ 
		//Restart the animation 
		frame = 0; 
	}
	//Loop the animation 
	if( frame >= 61 ) 
	{ 
		frame = 0; 
	}
	return 0;
}